package com.liu.usky.rlzp.uskyrlzp.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.liu.usky.rlzp.uskyrlzp.entity.Test;
import com.liu.usky.rlzp.uskyrlzp.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("test-find")
@Scope(value = "request")
public class TestController {
    private final static ObjectMapper objectMapper = new ObjectMapper();

    @Autowired
    private TestService testService;

    @GetMapping(value = "getInfos",produces = "application/json")
    public List<Test> getInfos(){
        List<Test> re= new ArrayList<>();
        Test byId = testService.getById(1);
        re.add(byId);
        re.add(byId);
        return re;
    }

    @GetMapping(value = "getMapInfos",produces = "application/json")
    public String getMapInfos() throws JsonProcessingException {
        Map<String,Object> map = new HashMap<>();
        map.put("name","小花");
        map.put("age",28);
        map.put("sex","男");
        map.put("address","重庆");
        String result = objectMapper.writeValueAsString(map);
        return result;
    }
}
